package com.jingdong.interview;

import java.util.Scanner;

/**
 * @author ZhangyiA
 * @describe:
 * @date 2021/07/06
 */

public class Two_BowlingGame {

    public int calDigitalTriangle(int[][] triangle , int n){
        int[][] dp = new int[n + 1][2 * n];
        for(int i = 1 ; i <= 2 * n - 1 ; i ++){
            dp[n][i] = triangle[n][i];
        }
        for(int i = n - 1 ; i >= 1 ; i --){
            for(int j = 1 ; j <= 2 * i - 1 ; j ++){
                int x = Math.max(dp[i + 1][j] , dp[i + 1][j + 1]);
                int y = Math.max(x , dp[i + 1][j + 2]);
                dp[i][j] = triangle[i][j] + y;
            }
        }

        return dp[1][1];
    }

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[][] triangle = new int[n + 1][2 * n];
        for(int i = 1 ; i <= n ; i ++){
            for(int j = 1 ; j <= 2 * i - 1 ; j ++){
                triangle[i][j] = input.nextInt();
            }
        }
        Two_BowlingGame game = new Two_BowlingGame();
        System.out.println(game.calDigitalTriangle(triangle , n));
    }

}
/*
4
3
5 9 4
5 2 1 3 9
3 7 2 8 4 2 6
* */